// import { combineReducers, applyMiddleware, createStore } from 'redux'
import { configureStore, EnhancedStore, Dispatch } from "@reduxjs/toolkit";
import loggerMiddleware from "./middlewares/logger";

import userStore, { userOtherActions } from "./modules/userStore";
import mainStore from "./modules/mainStore";
import menuStore from "./modules/menuStore";

// import { createLogger } from '@/utils/logger'

// const logger = createLogger('store')

// const store: EnhancedStore = configureStore({
const store = configureStore({
    reducer: {
        user: userStore.reducer,
        main: mainStore.reducer,
        menu: menuStore.reducer,
    },
    middleware(getDefaultMiddleware) {
        // return getDefaultMiddleware.concat(loggerMiddleware)
        const mws = getDefaultMiddleware();
        mws.push(loggerMiddleware);
        return mws;
    },
});

const actionCreators = {
    ...userStore.actions,
    ...userOtherActions,
    ...mainStore.actions,
    ...menuStore.actions,
};

export type RootState = ReturnType<typeof store.getState>;

const { dispatch }: { dispatch: Dispatch<any> } = store;
export { userStore, actionCreators, mainStore, store, dispatch };

export default store;
